#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <stdio.h>

#include <sys/ioctl.h>

#define BLKGETLASTSECT  _IO(0x12,108) /* get last sector of block device */
#define BLKSETLASTSECT  _IO(0x12,109) /* get last sector of block device */
#define BLKSSZGET  _IO(0x12,104)/* get block device sector size */
//void dumpIt(void *, int );

struct blkdev_ioctl_param {
	unsigned int block;
	size_t content_length;
	char * block_contents;
};

main(int argc, char *argv[])
{
  int filedes, rc=0, blksz=0;
  char *lastblock;
  struct blkdev_ioctl_param ioctl_param;
unsigned int lba;
int orig_blksize;
  ioctl_param.block = 0;
char *buf;

  filedes = open("/dev/sda1", O_RDONLY );
  printf("  open filedes: %d\n", filedes);

  rc = ioctl(filedes, BLKSSZGET, &blksz) ;
  lastblock = (char *) malloc( blksz + 8 );
  ioctl_param.content_length = blksz;
  printf("  block size appears to be %d\n", blksz);
  orig_blksize=blksz;

/*  #memset( lastblock, 'z', blksz + 8  );
  #ioctl_param.block_contents = lastblock;

  #rc = ioctl(filedes, BLKGETLASTSECT, &ioctl_param) ;
  #printf("  last sect ioctl rc: %d\n", rc);

  #lastblock[blksz + 1] = '\0';
  #printf("  Last Block: \n%s<--\n", lastblock);
*/
lseek(filedes, 2*512, SEEK_SET);
buf = malloc(512);
read(filedes, buf, 512);
    int i=0;
    while(i<512 )
    {
            printf("%c", buf[i]);
            i++;
    }

//	dumpIt(buf,512);
//  return 0;
}

